home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ccdl151e.zip / CC386.DOC < prev    next >
Text File  |  1997-06-14  |  43KB  |  1,267 lines

  1. 1.1) General introduction
  2. 1.2) Liability and authorship
  3. 1.3) General setup issues
  4. 1.4) Command line switches
  5. 1.5) Credits
  6. 2.1) ANSI compatability
  7. 2.2)  Missing features
  8. 2.3) C++ style features
  9. 2.4) Known bugs
  10. 3.1) Standard run-time libraries.
  11. 3.2) DOS libraries
  12. 4.1) Implementation-dependent keywords
  13. 4.2) Implementation-dependent preprocessor functions
  14. 4.3) Phi-text compatability
  15. 5.1) Errors
  16. 6.1) Stack frames
  17. 6.2) ASM interface
  18. 6.3) Segmentation
  19. 6.4) Optimizations
  20. 7.1) Description of directory tree
  21. 7.2) Porting
  22.                                                 
  23. 1.1) General introduction
  24.  
  25. CC386 is a generic 386 DOS C compiler.  Every effort has been made to
  26. have it recognize standard ANSI syntax; however it should NOT be
  27. expected to produce code conforming to the ansi standards, especially 
  28. in regard to floating point.  CC386 outputs assembly language code
  29. suitable for TASM and NASM, and possibly it will work with MASM.
  30.  
  31. This package includes various support programs and libraries required
  32. to build code that will run under an MSDOS DPMI server.  TRAN's PMODE
  33. is used for the server; so if there is no memory management software
  34. programs generated by this package will still work.
  35.  
  36. You need TASM and TLINK to use this package.  You can get by with 
  37. WLINK; however TASM is still a requirement.  The compiler itself will
  38. generate NASM compatabile code, however this package is not sufficient
  39. to have that code actually run under DOS.
  40.  
  41. This package consists of the compiler, some borland DPMI stubs 
  42. currently needed for the compiler, run-time libraries for DOS, and 
  43. header files.  Seperate packages have the source for the compiler and
  44. the run-time libraries.
  45.  
  46. Additionally, the package includes a program 'CL386' which will
  47. call the compiler, TASM, and TLINK to create programs for you.
  48.  
  49. Warning: you must have a version of TASM earlier than version 4.1;
  50. TASM 4.1 has some bugs.  The code was tested with 4.0; it will probably
  51. work with 3.0 and maybe even 2.0.
  52.  
  53. Part of the run-time libraries is a debug-style debugger that can be
  54. linked into the code.  Note that this debugger will NOT work inside
  55. a win95 DOS box; however the rest of the package will.
  56.  
  57. New features and bug fixes:
  58.  
  59. revamp of floating point to make it at least work a little.  Now that I
  60. have a coprocessor :).  
  61.  
  62. exception handling that works, including a floating point exception
  63. handler that will catch it if you use floating point when there is
  64. no coprocessor.
  65.  
  66. revamp of all the implicit cast operations to make them work properly
  67.  
  68. fix to code generation for pointers to functions
  69.  
  70. fix to the bit-size variables used in structures
  71.  
  72. inline assembler recognizes ALL 486 opcodes (32-bit addressing modes only)
  73.  
  74. various fixes to the debugger
  75.  
  76. addition of SPAWN functions to the run-time library
  77.  
  78.  
  79. This program IS capable of compiling itself and having the image run;
  80. I do not distribute this latter image because it will not run on a 386
  81. when there is no FP coprocessor.
  82.  
  83. 1.2) Liability and authorship
  84.  
  85. This compiler is presented on an 'as-is' basis without any guarantee of
  86. usability or fitness for any given application.  Risks associated with
  87. using it, including financial loss or loss of life are not the 
  88. responsibility of the authors.  However, this compiler is intended as 
  89. an educational tool, and is not to be used commercially in any case 
  90. without the express written consent of the authors.
  91.  
  92. The original author is Matthew Brandt.  As he left it it was a K&R 
  93. style compiler with no floating point and minimal preprocessor support, 
  94. targeted only for the m68k.  Much of the work was done on a Unix 
  95. machine and later ported to DOS.  You can find his version on one of 
  96. the Motorola file sites if you wish to compare.  The current version 
  97. has been updated extensively to support a variety of ANSI constructs as 
  98. well as i386 support and a better preprocessor.  However, parts of
  99. the program still reflect Mathew's work.
  100.  
  101. I have done my part of the coding with 16 and 32 bit MSDOS compilers.
  102. This version of the code has NO dos-specific features in it and should
  103. be portable to any 16 or 32 bit ANSI compiler.
  104.  
  105.  
  106. 1.3) General setup issues
  107.  
  108. To install the version which creates DOS executables, run the install.bat
  109. file.  You need to give it a file name:
  110.  
  111. install C:
  112.  
  113. will install the necessary files on drive C:.  A directory tree will
  114. be made under \CC386 and all necessary files will be copied there.
  115. Read the file INTRO.DOS for a brief overview of how to create programs
  116. for DOS.
  117.  
  118.  
  119. The only thing really needed for the compileer to work is a pointer
  120. to the include directories.  These may be specified in the environmnt
  121. variable 'CCINCL' or with the /I command line switch.  I normally set
  122. CCINCL=\cc386\include to get at the ansi headers and then use /I if any 
  123. other directories are required.  If you use the install.bat program
  124. CL386 will take care of the include and library issues via its configuration
  125. file and there is no other setup required other than to run the install
  126. program.
  127.  
  128. 1.4) Command line switches
  129.  
  130. Switches prefixed with a '+' or '-' may be turned on orr off.  The
  131. last occurance of the switch determines the state.  For these switches
  132. '/' is equivalent to '-'.  Note that codegen parameters must generally
  133. be the same for all modules in a program, or unpredictable results will
  134. occur.
  135.  
  136.  
  137. +e  - make error file
  138.  
  139. +i  - make preprocessed file
  140.         default is -i
  141.         
  142. /ffile - process arguments in file 'file'
  143. +l  - make LST file
  144.         default is -l
  145. /w-all - no warnings, errors only
  146.         warnings may also be suppressed individually.  See ERROR.DOC
  147. -A  -  disable ANSI compatability and enable some non-standard features
  148.         default is +A
  149. /C  - codegen params 
  150.         /C+d - display internal diagnostics 
  151.         /C-b - no BSS 
  152.         /C-l - don't put C source in the ASM file
  153.         /C-m - don't mangle symbols with a leading underscore
  154.         /C+p - pack variables for space.  On a 68020+ minimize at word 
  155.                 alignment
  156.         /C+r - reverse order of bit ops 
  157.         /C+F - (386) force the TASM .MODEL directive to use FLAT mode
  158.                 This may become the default in some future release.
  159.     /C+N - generate NASM code
  160.         /C-R - use stack pointer rather than link registers
  161.  
  162.         default is /C+blmR-prFN
  163. /Dxxx  - define a macro 'xxx' 
  164. /E##  - max number of errors to generate 
  165. /Idirs  - specify include directories.  use a semicolon to seperate multiple 
  166.           directory specifications.  The directories specified by the 
  167.           environment variable "CCINCL" are always searched first.  
  168. /O  - Optimizer params 
  169.         /O-Rxxx Turn off register optimizations.  In place of the xxx 
  170.                 put any combination of:
  171.  
  172.                 a - turn off address rigister optimizations
  173.                 f - turn off floating point register optimizations
  174.                 d - turn off data register optimizations
  175.  
  176.         default is all register optimizations enabled
  177.  
  178.  +S  - reserved, no use (yet)
  179.         default is -S
  180.  
  181. Compiler will look for the symbol CC386 (or CC68K) in the environment.
  182. If it finds it, it will evaluate any command line arguments in it
  183. prior to evaluating the command line.  Note that command line 
  184. parameters will override the environment variable; in particular 
  185. specifying a search path both in the environment var and on the command 
  186. line will result in loss of the search-path environment.  There is an 
  187. alternate environment variable CCINCL which specifies include paths 
  188. which will be appended to the command line specification.
  189.  
  190. 1.5) Credits
  191.  
  192. The following people contributed source code to this program.
  193.  
  194. Matthew Brandt:  original K&R C compiler
  195. Thomas Pytel (TRAN):  DPMI extender for DOS
  196. Kirill Joss: CL386 compiler shell
  197. David Lindauer:  Ansification, preprocessor, run-time libraries,
  198.     386 code gen, miscellaneous enhancements to original compiler
  199.  
  200.  
  201. Many people were instrumental in locating bugs, I'd like to acknowledge
  202. two who were especially helpful with *lots* of testing:
  203.  
  204. Johann Klockars
  205. Kirill Joss
  206.  
  207. And thanks to David Gurevich and Kirill Joss for helpful suggestions on 
  208. packaging.
  209.  
  210. 2.1) ANSI compatability
  211.  
  212. This compiler is meant to be ANSI compatible at the source level.  However
  213. I have never seen the ANSI documentation for what that means; If 
  214. you find something it doesn't do, let me know!
  215.  
  216. However, there is no guarantee that code generated will meet ANSI
  217. runtime requirements in terms of evaluation ordering, especially with
  218. casts.  floating point is done using the host coprocessor , and is NOT
  219. adjusted for ANSI/IEEE compatability.
  220.  
  221. The run-time library is designed to act like an ANSI library; however 
  222. the internals are most likely somewhat different.  Especially since I
  223. did away with static buffers where possible.
  224.  
  225.  
  226. 2.2)  Missing features
  227.  
  228. The following are known to be missing:
  229.  
  230. a) libraries don't handle any kind of floating point
  231. b) expressions of the form:
  232.     (T)
  233.  
  234. are not handled correctly when T is a typedef
  235.  
  236. 2.3) C++ style features
  237.  
  238. The C compiler has some rudimentary C++ support.  It recognizes:
  239.  
  240. 1) Overloaded functions (but not the overload keyword)
  241. 2) Variable declarations anywhere
  242. 3) Reference variables
  243. 4) Function parameter defaults
  244. 5) Stricter type checking
  245. 6) Improved init of static pointers and reference variables
  246. 7) Detailed C++ error messages
  247.  
  248. classes and C++ keywords aren't yet supported.
  249.  
  250. To enable these features use the extension .CPP on your input file
  251.  
  252. 2.4) Known bugs
  253.  
  254. The following known bugs exist:
  255.  
  256. a) Expression evaluation is recursive.  With a 4K compiler stack 
  257. the limit is approximately something like:
  258.  
  259.     a = (b()+(c()+(d()+(e()+f()))));
  260.  
  261. Beyond this unpredictable results will occur.  Raise the stack limit
  262. or rearrange the expression with higher order parenthesis to the left.
  263. Notice this would not be a problem without the grouping parenthesis
  264. because the compiler wouldn't have to maintain so many contexts.  I 
  265. compile the compiler with a 20K stack 
  266.     
  267. b) Floating point may or may not work.  A floating point library will
  268. be added later and this will be checked out
  269.  
  270. d) expressions such as :
  271.  
  272.     a = b = c;
  273.  
  274. may not return the correct value to anything other than the rightmost
  275. assignment.  In general it will work, but if there are multiple 
  276. implicit casts going on from one assigment to the next it may not work
  277. correctly.
  278.  
  279. e) % may not work properly for signed divisions.  The sign may be
  280. wrong but the value will be correct.  This may or may not be a problem,
  281. I haven't analyzed it.
  282.  
  283. f) long and unsigned constants will not be optimized or evaluated 
  284. correctly when there are two or more of them in an expression (type may
  285. not propogate)
  286.  
  287. g) The identifier 'pascal' is a standard keyword rather than something
  288. a user may redefine.
  289.  
  290. 3.1) Standard run-time libraries.
  291.  
  292. libs were implemented according to 'The Waite Group's Essential Guide 
  293. to ANSI C'- ISbN 0-672-22673-1.  My copy is circa 1989.
  294.  
  295. Floating point library functions are not supported at this time, as I
  296. have no way to test them.  This includes things like atof and difftime
  297. as well as most of the math libraries.
  298.  
  299. All the functions in this book were implmented except floating point.
  300. However, process control stuff is kind of sketchy at this time.  Most
  301. of the IO library, part of the time library, and the malloc library
  302. functions require operating system support.  Documentation for this
  303. is provided with the run-time library sources; however this
  304. package contains sufficient code to use DPMI as the operating system.
  305.  
  306. There may be a variety of cases where things don't work as expected.
  307. For example scanf will only read one line no matter what... when a 
  308. function such as strftime requires a buffer length to be given the
  309. results are undefined if the text length exceeds the buffer length.  
  310. Also I just found out the opening a file with the 'a' attribute is 
  311. supposed to override any attempt to set the position for write in the
  312. file... in this implementation all it does is position to the end of 
  313. the file at open time.
  314.  
  315. The libraries were originally designed in a reentrant fashion; however
  316. this breaks much standard code and the version of the libraries 
  317. included here has static buffers where called for.
  318.  
  319. ERRNO isn't supported at this time.
  320.  
  321. Many of the library functions depend on having the startup/rundown code
  322. included.  This code initializes a few global variables and executes
  323. any startup/rundown functions the libraries need for initialization
  324. and cleanup.
  325.  
  326. To use the libraries two files must be included in your link.  First is
  327. the startup module (c0dos or c0dosd) and second is the library itself (cldos).
  328. An example build if _main is defined in q.c:
  329.  
  330. cc386 q.c
  331. tasm /ml /m2 q.c
  332. tlink c0dos q,q,q,cldos
  333.  
  334. will build q.exe.  Note that the startup module MUST be the first object
  335. module specified as it defines the segmentation setup required.
  336.  
  337. Two startup modules are provided; c0dos is a standard C startup module.
  338. c0dosd is the same module but it will draw in a debugger from the library
  339. (approximately 16K) and call it rather than execute your code.  The debugger
  340. is somewhat similar to DEBUG.  When the debugger starts up the EIP and
  341. registers will be set to the values they would have at the beginning
  342. of your _main function.  The debugger traps several exceptions including
  343. int 3 so you can put int 3 in your code at places you want to debug.
  344. Warning!  The debugger will NOT work in a DOS box in windows 95, as I
  345. could not get appropriate access to exceptions.
  346.  
  347. The startup modules use TRAN's PMODE to manage pmode resources.  I
  348. use version 3.07... I had to modify the class names in his segment
  349. declarations to make them different from the 32-bit code segments but other
  350. than that they are his release.  I have included the sources as per his
  351. licensing in msdos\pmode307.
  352.  
  353. I manage several exceptions; traps 6,13, and 14 are all routed through
  354. the signal-handling code; by default the print general protection fault and
  355. exit but you can trap them using the signal mechanism if you want.  
  356. Unless you are in a DOS box...  likewise traps 7, 8, and 16 relating 
  357. to floating point are routed through the signal handling code unless
  358. you are in a DOS box.  The default signal handling code just prints a
  359. message and jumps to the program exit point...
  360.  
  361. I also manage ctrl-c interrupt from DOS (but not ctrl-brk from BIOS, that
  362. is handled via the DOS interrupt) and exit the program cleanly if ctrl-c
  363. is pressed.  Note that ctrl-c will even exit the debugger!  I should
  364. probably fix that...
  365.  
  366. 4.1) Implementation-dependent keywords
  367.  
  368. a) The following implementation-dependent keywords have been added
  369.  
  370. i386        use
  371. _interrupt    Generate a function which may be used
  372.         as a trap/interrupt.
  373. _genbyte    Generate data in the code segment
  374. _absolute    Allocate a global variable at 
  375.         an absolute address.  Such variables 
  376.         will be directly addressable.
  377. pascal        force the function declaration to use
  378.         pascal calling conventions.
  379.  
  380. b) The following implementation variables have been added.  these 
  381. variables directly access the assembly language registers they name.  
  382. Note they should be used with caution and may change periodically at
  383. the compiler's discretion.  Also, casts of them or assignements to 
  384. them may change the machine state functionally... and wreck the
  385. code the compiler has generated.
  386.  
  387. i386
  388. _EAX _EBX _ECX _EDX _ESP _EBP _ESI _EDI
  389.  
  390. the 386 compiler also knows the keyword 'asm' which is an escape to
  391. allow inline assembly.  The syntax is:
  392.  
  393. asm my_instruction;
  394.  
  395. or 
  396.  
  397. asm {
  398.     my list of instructions;
  399.     }
  400.  
  401. The compiler catches most errors in inline assembly code at compile 
  402. time.  It will also translate the names of local variables into
  403. proper stack-based addressing modes.
  404.  
  405. 4.2) Implementation-dependent preprocessor functions
  406.  
  407. the preprocessor is more-or less ansi compatible.
  408.  
  409. The following #pragma statements are supported:
  410.  
  411. #pragma regopt xxx
  412.     now obsolete
  413.  
  414. #pragma startup xxx #
  415.     xxx may be any function name
  416.     # may be a priority value from 20 - 90 (other values are used
  417.     by the run-time library)  Higher priority functions get run 
  418.     first.
  419.  
  420.     This option tells the compiler to inform the startup routines
  421.     that this function should be run prior to calling main.
  422.  
  423. #pragma rundown xxx #
  424.     xxx may be any functionn name
  425.     # may be an integer value from 20-90 (other values are used by
  426.     the run-time library).  Higher priority functions get run 
  427.     first.
  428.  
  429.     This option tells the compiler to inform the startup routines
  430.     that this function should be run after main exits.
  431.  
  432. The following macros are predefined:
  433.  
  434.     _i386_ (386 only) compiler is generating 386 code
  435.     _m68k_ (68k only) compiler is generating 68K code
  436.  
  437.     __cplusplus if the compiler is allowing C++ extensions
  438.     __FILE__ the file name of the source file as a string
  439.     __DATE__ The date as a string
  440.     __TIME__ The time as a string
  441.     __LINE__ the line number as a number
  442.  
  443. #if macros can use defined(xxx) to determine if a macro is defined.
  444.  
  445. 4.3) Phi-text compatability
  446.  
  447. This compiler is capable of understanding 'phi-text' which is an 
  448. extended text-based character set.  It is somewhat preferable to 
  449. UNICODE for western programmers as it does not encompass thousands of 
  450. characters that are little used by main-stream westerners.
  451.  
  452. Phi text is a banked character set.  Each character in its full
  453. form is 32-bits; this encompasses the following information:
  454.  
  455. cwb:     a number from 32 to 127 describing the character
  456. bank:   a bank from 0 to 15.  BANK 0 is the ASCII character set with
  457.     some modifications to control characters.
  458.  
  459. basic Attributes:  BOLD, UNDERLINE, ITALIC, HIDDEN, and REVERSED 
  460.     attributes.  BLINKING may be substituted for ITALIC however we 
  461.     normally use ITALIC.
  462.  
  463. color: 16 color renditions.  The colors have been chosen to reflect 
  464.     complementary colors.  Foreground and background may be 
  465.     specified for each character.
  466.  
  467. size    16 size attribute
  468. font:    16 font attribute
  469.  
  470.  
  471. 32 bits per character is a bit much for some applications; an 
  472. application may elect to ignore certain fields.  This compiler ignores
  473. ALL fields but the bank and the CWB (although it may look briefly
  474. at attributes, I don't remember).  Internally, the characters are thus
  475. represented with 16-bit fields in this compiler.
  476.  
  477. To ease the storage requirements of such a character set, there exists
  478. a 'streamed' form of phi-text.  This takes advantage of the notion that
  479. attributes are not likely to change as rapidly as the character 
  480. information.  Basically, if the high bit of a streamed byte is set
  481. it indicates that control information is embedded which indicates the
  482. new attributes.  There is also a 'repeat' code so that long strings
  483. of repeating characters (for example spaces) get packed together.  This
  484. is not quite as efficient as tabbing but in the long run it works out
  485. better because there are several situations where such strings may
  486. occur in phi-text and they do NOT always involve spaces.  In this
  487. compiler, the incoming text is in streamed format (which defaults to
  488. ASCII unless an appropriate editor is used).  The streamed format is
  489. converted to a flat format and all information is stripped except that
  490. essential to detecting the character.  Preprocessing is done on the
  491. flat version... but when the scanner starts looking for tokens it then
  492. converts the flat version back to stream (minus colors and attributes)
  493. for more effeciency in the parser and back end.  If the source file
  494. is streamed phi-text the list and assembly files will also be streamed
  495. phi-text; color information is added to the list file just to
  496. make it a little flashy, although I have a monochrome monitor so the
  497. colors I picked may be awkward.
  498.  
  499. One problem exists with streamed formats: in case of an error situation
  500. it is possible to lose important synchronization and so wreck more than
  501. a single character.  For this reason streamed phi-text is partially
  502. synchronizing; at the beginning of each line all attribute information
  503. defaults back to a standard default.  In this way one never loses more
  504. than a complete line in the presence of simple errors.  And even at 
  505. that a smart editor could be designed to help one recover from such
  506. simple errors... provided that errors occurred often enough to be worth
  507. the effort.
  508.  
  509. We have seen that phi-text is composed of 16 banks with 96 characters 
  510. per bank, for a total of 1536 characters.  The first bank is pure
  511. ASCII, with a few modifications, but what are the other banks?
  512. About half of them are currently unused.  Of those some have been
  513. deliberately reserved for application speccific and system-specific
  514. uses by the designer of phi-text.  The defined characters can be broken 
  515. roughly into the following groups:
  516.  
  517. 1) ASCII characters
  518. 2) European extensions (accented characters)
  519. 3) greek characters
  520. 4) cyrillic characters
  521. 5) line drawing characters
  522. 6) mathematics characters
  523. 7) miscellaneous characters
  524.  
  525. While it IS possible to extend certain C operators with more compact
  526. character representations in a compiler like this one, use of phi-text
  527. has been limited to allowing greek and cyrillic characters in variable
  528. names, and to allowing things in boxes to be treated as comments.  The
  529. primary editor for phi-text has an extension that allows usage of the
  530. arrow keys to draw lines on the screen and this makes beautifying code
  531. a snap.
  532.  
  533. For more information about phi-text, contact:
  534.  
  535. Paul McKneely
  536. P.O. BOX 5641
  537. Pasadena, TX, 77508
  538.  
  539. email: gecko@onramp.net 
  540.  
  541. 5.1) Errors
  542.  
  543. This is a list of possible errors.  There are two types of errors... 'Errors'
  544. and 'Warnings'.  an 'Error' signifies an event which the compiler cannot
  545. handle, whereas a 'warning' is a diagnostic which indicates that something
  546. is possibly wrong but the compiler will make assumptions about it.
  547.  
  548. This list is slightly outdated; it is missing new errors which the
  549. inline assembler can generate.
  550.  
  551. Each 'warning' will have a value in parenthesis, this value may be used
  552. on the command line to supress the warning.  the value 'all' may be used
  553. to supress all warnings.  Errors may not be suppressed.
  554.  
  555. Example
  556.  
  557. cc -w-ieq a.c  ; Suppress the 'Possibly incorrect assignment' warning.
  558. cc -w-all a.c    ; Suppress ALL warnings
  559.  
  560. Some of these errors result when the compiler is in C++ mode.
  561.  
  562.  
  563.  
  564.  
  565.  
  566. Error: _int keyword not allowed in Pascal declarations
  567.  
  568.     Pascal declarations may not be used as traps or interrupts.
  569.  
  570. Error: Ambiguity between %s and %s
  571.  
  572.     C++.  Compiler cannot choose between two almost equivalent
  573.     overloaded definitions.
  574.  
  575. Warning: ('cln') Argument list too long %s
  576.  
  577.     Argument list for the function call specified is too long.  Compiler
  578.     ignores the extra args.
  579.  
  580. Error: Argument list too long in redeclaration of function '%s'
  581.  
  582.     A prototyped function has been redeclared with a different argument list
  583.  
  584. Error: Argument list too short %s
  585.     
  586.     Too few parameters have been supplied in a function call.
  587.  
  588. Error: Argument list too short in redeclaration of function '%s'
  589.  
  590.     A prototyped function has been redeclared with a different argument list
  591.  
  592. Error: Bit field must be signed or unsigned int
  593.     ANSI C requires a bit field to be of one of these types.
  594.     If extensions are allowed bit fields can be of any integer 
  595.     type.
  596.  
  597. Error: Bit field only allowed on scalar types
  598.  
  599.     Bit fields can only be used on integral types.
  600.     This error will occur if in non-ansi mode and you use any
  601.     non-integral type as the basis for a bit field.
  602.  
  603. Error: Bit field too big
  604.  
  605.     Bit fields must fit within the processor word size.
  606.  
  607. Warning: ('pro') Call to function '%s' with no prototype 
  608.  
  609.     A function call has been made to a function that has not been
  610.     previously declared.  Compiler guesses at argument types.
  611.  
  612. Error: Cannot cast %s
  613.  
  614.     C++.  Some casting of classes is not allowed.
  615.  
  616. Error: Cannot define a pointer or reference to a reference
  617.  
  618.     C++.  Reference variables are treated specially in this regard
  619.  
  620. Error: Cannot initialize '%s'
  621.  
  622.     An error occurred while trying to process a variable initialization
  623.  
  624. Error: Cannot modify a const val
  625.  
  626.     a CONST value may not be modified
  627.  
  628. Error: Cannot open file \"%s\" for read access
  629.  
  630.     An include file was not found
  631.  
  632. Error: Cannot overload 'main'
  633.  
  634.     C++.  main() must not be overloaded
  635.  
  636. Error: Cannot take address of bit field
  637.  
  638.     Pointers to bit fields not allowed
  639.  
  640. Error: Cannot use bit field as a non-member
  641.  
  642.     Only structure members may have a bit field qualifier.
  643.  
  644. Warning: ('cno') Code has no effect
  645.  
  646.     This line of code compiled to nothing
  647.  
  648. Error: Constant value expected
  649.  
  650.     In general initializers must be constant values.  Some others
  651.     must as well
  652.  
  653. Error: Constructor/destructor must be untyped
  654.  
  655.     C++ can't type constructors/destructors
  656.  
  657. Error: Continue not allowed    
  658.  
  659.     Not in scope where a continue makes sense
  660.  
  661. Warning: ('cnv') Conversion may truncate ignificant digits 
  662.  
  663.     An implicit cast may result in loss of significant digits.  This
  664.     warning is NOT produced for explicit casts.
  665.  
  666. Error: Could not find a match for '%s'
  667.  
  668.     C++.  This function call is not prototyped either directly or
  669.     with an overload or defaulted function prototype
  670.  
  671. Warning: ('dpc') Dangerous pointer cast    
  672.  
  673.     If you get this, it will happen when the size of the pointer is
  674.     not the same as the size of the (scalar) type youy are using
  675.     with it.
  676.  
  677. Error: Declaration expected
  678.  
  679.     Parser got a statment or other value when it was expecting a
  680.     declration.
  681.  
  682. Error:   Declaration not allowed here 
  683.  
  684.     Parser found a declaration when it was expecting a statement
  685.  
  686. Error: Default missing after parameter '%s'
  687.  
  688.     C++... this parameter was assumed to have a default which is missing.
  689.  
  690. Error: Destructor for class '%s' expected
  691.  
  692.     C++.  A destructor was expected.
  693.  
  694. Error: Duplicate case %d
  695.  
  696.     Two case statements evaluate to the same value
  697.  
  698. Error: Duplicate label '%s'    
  699.  
  700.     The label occurs twice in the same procedure.
  701.  
  702. Error: Duplicate symbol '%s' 
  703.  
  704.     The symbol is being redefined.
  705.  
  706. Error: Ellipse (...) not allowed in Pascal declarations
  707.  
  708.     Pascal-style declarations may not have variable arguments.
  709.  
  710. Error: Expected '%c'
  711.  
  712.     The compiler expected a specific character or token.
  713.  
  714. Error: Expression expected
  715.  
  716.     The compiler was ready to parse an expression but found something
  717.     else
  718.  
  719. Error: File ended with comment in progress
  720.  
  721.     Comments must have an ending point within the same file or 
  722.     include file.
  723.  
  724. Error: File name expected in #include directive
  725.  
  726.     #include directive must have a file name
  727.  
  728.  
  729. Error: Function declaration not allowed here
  730.  
  731.     A function declaration was attempted in an invalid place, for
  732.     example inside a structure or inside another function.
  733.  
  734. Warning: ('ret') Function should return a value
  735.  
  736.     This error occurs when a function is not of type 'void'
  737.     and you exit without returning a value.
  738.  
  739. Error: Identifier expected
  740.  
  741.     The parser was expecting a variable/function name.
  742.  
  743. Error: Illegal call to main() from within program 
  744.  
  745.     C++.  C++ programs may not call main()
  746.                                                 
  747. Error: Illegal character '%c'
  748.  
  749.     The parser detected an illegal character sequence.
  750.  
  751. Error: Illegal pointer
  752.  
  753.     An attempt was made to use a non-pointer in a pointer context
  754.  
  755. Error: Illegal pure declaration syntzx of '%s'
  756.  
  757.     C++.  Virtual declaration syntax is wrong
  758.  
  759. Warning: ('irg')  Illegal register var '%s' 
  760.  
  761.     the size of the variable was too big for it to fit in a
  762.     register
  763.  
  764. Error: Illegal storage class specifier '%s'
  765.  
  766.     Conflicting or illegal specifier on a declaration.
  767.  
  768. Error: Illegal storage class specifier on '%s'
  769.  
  770.     Conflicting or illegal specifier on a declaration.
  771.  
  772. Error: Illegal typedef of '%s'
  773.  
  774.     Attempt to reuse a symbol name as a typedef.
  775.  
  776. Error: Illegal use of reference operator
  777.  
  778.     Attempt to use '&' in a context where it is not permitted.
  779.  
  780. Error:  Illegal use of void pointer
  781.  
  782.     Cannot take the size of a void pointer.
  783.  
  784. Error: Inserted '%c'
  785.  
  786.     The parser guessed at a symbol to insert.
  787.  
  788. Error: Invalid '&' on register var '%s'    
  789.  
  790.     Cannot take the address of a register
  791.  
  792. Error: Invalid floating point
  793.  
  794.     Cannot use floating point in certain types of math functions
  795.     (e.g. logic functions)
  796.  
  797. Error: Invalid preprocessor directive '%s'
  798.  
  799.     Preprocessor directive is unknown
  800.  
  801. Error: Invalid trap id
  802.  
  803.     CPU-specific.  Indicates a cpu operation (int or trap) was called
  804.     with an identifier that is too large
  805.  
  806. Error: '%s' is not a function
  807.  
  808.     Cannot call non-functions.
  809.  
  810. Error: '%s' is not a label
  811.  
  812.     Cannot jump to non-labels.
  813.  
  814. Error: Local class functions not supported
  815.  
  816.     C++. Cannot support class definitions as local variables
  817.  
  818. Error: Local variables may not be used as parameter defaults
  819.  
  820.     C++ .Paremeter defaults must be in scope prior to calling the function
  821.  
  822. Warning: ('lli') long long int type not supported, defaulting to long int
  823.  
  824.     long long int type will parse correctly but it is unsupported
  825.  
  826. Error: Lvalue expected
  827.  
  828.     cannot assign to the address of a variable
  829.  
  830. Error: Macro substitution error
  831.  
  832.     Macro expansions are limited to 4096 characters
  833.  
  834. Error: Misplaced else
  835.  
  836.     Unexpected else found in input stream
  837.  
  838. Error: '%s' must be a predefined class or struct
  839.  
  840.     C++.  Cannot work with this structure/class because it has not
  841.     been fully defined.
  842.  
  843. Warning: ('zer') No memory allocated for '%s'    
  844.     
  845.     an unsized array has no initializers either.
  846.  
  847. Warning: ('nsf') Nonexistant static func '%s'    
  848.  
  849.     a static function was prototyped but never declared
  850.  
  851. Warning: ('npo') Nonportable pointer conversion
  852.  
  853.     An implicit  pointer conversion may result in code that compiles
  854.     incorrectly with other C compilers
  855.  
  856. Error: Non-scalar array index
  857.  
  858.     Array indexes must be of integral type
  859.  
  860. Error: Numeric constant is too large
  861.  
  862.     an integer or hex constant was too large for the base type,
  863.     or the non-fractional part of a floating-point number could
  864.     not fit in a long-integer.
  865.  
  866. Error: Pointer type expected
  867.  
  868.     A pointer was expected.
  869.  
  870. Warning: '(ieq') Possible incorrect assignment
  871.  
  872.     the symbol '=' was used at the outer scope in an if statement
  873.     expression.
  874.     This could be intended, but often is a mistype of the symbol
  875.     '==' so the compiler warns you.
  876.  
  877. Warning: ('san') Possible superfluous &
  878.  
  879.     & isn't needed when taking the address of an array.  This is a junk
  880.     message; ansi C doesn't care either way.
  881.  
  882. Warning: ('sud') Possible use of '%s' before assignment
  883.  
  884.     A variable has been used but it possibly has not been initialized
  885.     with a value
  886.  
  887. Error: Reference initialization needs lvalue
  888.  
  889.     C++.  Reference syntax calls for something whose address can be
  890.     taken.
  891.  
  892. Error: Reference member '%s' in a class with no constructors
  893.  
  894.     C++. The reference variable cannot be initted at class startup because
  895.     the constructor is supposed to do it/
  896.  
  897. Error: Reference variable '%s' must be initialized
  898.  
  899.     C++.  Cannot change what a reference variable equates to
  900.     at run-time.
  901.  
  902. Error: Return type is void    
  903.  
  904.     Attempt to return a value from a void function
  905.  
  906. Error: Size is unknown or zero
  907.  
  908.     Attempt to use the size of a variable with a type that has
  909.     been forward declared. 
  910.  
  911. Error: Size of '%s' is unknown or zero
  912.  
  913.     Attempt to use the size of a variable with a type that has
  914.     been forward declared. 
  915.  
  916. Error: Startup/rundown function '%s' is unknown or not a function
  917.  
  918.     A function named in the '#pragma startup' or '#pragma rundown'
  919.     is either not a function or is not defined
  920.  
  921. Error: String constant too long
  922.  
  923.     A multi-line string is too long.
  924.  
  925. Warning: ('spc') Suspicious pointer conversion
  926.  
  927.     A pointer operation is being performed on pointers which have
  928.     different base types.
  929.  
  930. Warning: ('fun') Static function '%s' is declared but never used
  931.  
  932.     This static function is just a space waster.
  933.  
  934. Warning: ('sud') Static variable '%s' is declared but never used
  935.     
  936.     This static variable is just a space waster.
  937.  
  938. Warning: '(fsu) Structure '%s' is undefined
  939.  
  940.     The compile completed with a structure whose type was never
  941.     defined.
  942.  
  943. Error: Switch argument must be of integral type
  944.  
  945.     Switch arguments must be integers.
  946.  
  947. Warning: ('tua') Temporary used for parameter %s
  948.  
  949.     C++. A constant was passed in a reference parameter and the compiler
  950.     automatically made a variable so the called function would be
  951.     happy.
  952.  
  953. Warning: ('tui') Temporary used to initialize %s
  954.  
  955.     The reference variable is initted with a constant; extra storage
  956.     had to be created for it.
  957.  
  958. Error: Too many initializers
  959.  
  960.     A structure/array has too many initializers
  961.  
  962. Error: Type expected in sizeof
  963.  
  964.     sizeof argument was not a type or variable
  965.  
  966. Error: Type mismatch
  967.  
  968.     Generic type mismatch
  969.  
  970. Error: Type mismatch in arg '%s'
  971.  
  972.     type mismatch for function calls
  973.  
  974. Error: Type mismatch in redeclaration of '%s'
  975.  
  976.     A variable has been redeclared with a different type from 
  977.     before.
  978.  
  979. Error: Type mismatch in return
  980.  
  981.     The value being returned does not match the function type.
  982.  
  983. Error: Unbalanced preprocessor directives
  984.  
  985.     #if- #endif directives were not balanced.
  986.  
  987. Warning:   Undefined label '%s' 
  988.  
  989.     The label should appear somewhere as there is a goto to it.
  990.  
  991. Error: Undefined symbol '%s' 
  992.  
  993.     This is an unknown symbol
  994.  
  995. Error: Unexpected '%s'
  996.  
  997.     This keyword was unexpected.
  998.  
  999. Warning: (' urc') Unreachable code
  1000.  
  1001.     Code stream can never get here.
  1002.  
  1003. Warning: ('lun') Unused label '%s'    
  1004.  
  1005.     A label was declared but never used/
  1006.  
  1007. Error: User error: %s
  1008.  
  1009.     #Error directive results in this
  1010.  
  1011. Warning: ('sas') Variable '%s' is assigned a value which is never used
  1012.  
  1013.     After assignment to the var, there is no subsequent use
  1014.  
  1015. Error: Variable '%s' cannot have a type qualifier
  1016.  
  1017.     C++.  ???
  1018.  
  1019. Error: Variable '%s' is not a class instance
  1020.  
  1021.     C++.  A class instance was expected.
  1022.  
  1023. Warning: ('sun') Variable '%s' is declared but never used
  1024.  
  1025.     This variable was declared but nothing ever referenced it.  Space
  1026.     waster.
  1027.                                                 
  1028. 6.1) Stack frames
  1029.  
  1030. There are a variety of options for stack frames.
  1031.  
  1032. a) Standard C-style stack frames.  An index register (EBP or A6) is 
  1033. used to point at a value between the paramenters and the function local 
  1034. variables; all local variables and function parameters are indexed from
  1035. this base register.  This is the default.
  1036.  
  1037. b)  The compiler can free the link register and index all local 
  1038. variables and function paremeters off the stack pointer
  1039.  
  1040. c) (68K only)  parameters lists may be located anywhere in memory;
  1041. the parameter list pointer is passed in A0.  A0 is then transfered to
  1042. A6 and parameters are indexed off A6.  Meanwhile local variables are 
  1043. indexed from the stack pointer.
  1044.  
  1045. On the 68K, several codegen options are available.  By default the
  1046. 68K compiler generates PIC code based around a 32K memory model.  A 
  1047. 68020 mode is available for speciying extended 68020 features such as 
  1048. enhanced addressing modes and specialized instructions.  Another option
  1049. is to generate 68000 code in such a way that a data section greater 
  1050. than 32K can be used.  The final option allows one to disable PIC mode
  1051. and generate code that will be placed at absolute addresses in memory.
  1052.  
  1053. 386 code is fairly straightforward.  It is a little more complex than 
  1054. need be because of the need to use special function registers for some 
  1055. operations like multiplies and shifts.  386 Code will be a little bulky
  1056. because of this need.
  1057.  
  1058. 68K code is position-independent.  All global data is accessed off of
  1059. register A5 or A6; function arguments are indexed off of A6 or A7; and 
  1060. the stack is indexed off A7.  String constants are indexed off the PC.  
  1061. Because of this, the total data size may only be 32K unless either the 
  1062. /C+2 or the /C+L or the /C+A options are used.
  1063.  
  1064. 6.2) ASM interface
  1065.  
  1066. the assembly language program must not modify any registers except the
  1067. scratch registers:
  1068.  
  1069. 386:    EAX,ECX,EDX
  1070.  
  1071. Parameters are passed on the stack, with the leftmost parameter at the 
  1072. lowest address.
  1073.  
  1074. In all assembly situations it is convenient to use an index register
  1075. to index the parameters.  The index register must be loaded with the
  1076. address of the first parameter (which will be the stack pointer + 4
  1077. if you don't push the index register, or the stack pointer +8 if you 
  1078. do).  Parameters normally take four bytes for the standard data types;
  1079. however double and long double types take 8 and twelve bytes 
  1080. respectively.  If you pass a structure by value the amount of stack 
  1081. space used is dependent on the size of the structure.
  1082.  
  1083. 6.3) Segmentation
  1084.  
  1085. The following segments or sections may appear in the output file:
  1086.  
  1087. 386 name    use
  1088. .CODE         Code and string constants
  1089. .DATA           Initialized global data
  1090. .?DATA          Unintialized global data
  1091. INITDATA        #pragma startup links
  1092. EXITDATA        #pragma rundown links
  1093. CPPDATA        C++ static initializations
  1094.  
  1095. The following switches affect code generation:
  1096.  
  1097. /C-b        combine the BSS with the DATA
  1098. /C-l        don't put line numbers in ASM file
  1099. /C-m        donn't mangle with underscores
  1100. /C+p        pack variables
  1101. /C+r        use reverse order for bit fields.
  1102.         Note that this option reverses the allocation order
  1103.         but does not reverse the value in the field.
  1104.  
  1105. The following #pragma statements affect code generation:
  1106.  
  1107. #pragma    regopt     - enable/disable register allocations
  1108. #pragma startup - name a routine to be executed on startup
  1109. #pragma rundown - name a routine to be executed on rundown
  1110.  
  1111. 6.4) Optimizations
  1112.  
  1113. the compiler performs the following optimizations:
  1114.  
  1115. a) Constant folding.  
  1116.  
  1117. When common math is done with constants, the compiler will evaluate 
  1118. the expression and replace it with a constant.
  1119.  
  1120. b) Reduction in strength
  1121.  
  1122. multiplies and divides are turned into shifts when appropriate.  Mods
  1123. are turned into ands when appropriate.
  1124.  
  1125. c) Target optimization
  1126.  
  1127. When the target for an assignment is known, a temp register will not
  1128. be allocated, but the target will be used directly.  This keeps us 
  1129. from generating dead temp registers that will later have to be 
  1130. optimized out of the icode.
  1131.  
  1132. d) Dead code elimination
  1133.  
  1134. Delete jumps to jumps, jumps to the next statement, and dead code.
  1135. also delete any temporaries that 2) came up with that are now
  1136. unused.
  1137.  
  1138. Note that the SETJMP libraries for example will NOT save the state of
  1139. floating point registers.  So there is a switch to disable optimization
  1140. into floating point registers in case you need to setjump to a routine 
  1141. that uses floating point.  Address and data register optimizations can
  1142. also be turned off.  See switches.doc.
  1143.  
  1144. e) reordering expressions
  1145.   In some cases the compiler generates better code if expressions are
  1146.   reordered; for example:
  1147.  
  1148.   a = a + 10;
  1149.  
  1150.   can be turned into a += 10 and better code gets generated.  Also,
  1151.   a lot of work has been put into optimizing usage of based/indexed
  1152.   modes of the processors when it can be done.  The present version 
  1153.   will even use index register scaling when possible!
  1154.     
  1155. f) base + index addressing modes
  1156.  
  1157. This compiler goes to some length to identify when base + index addressing
  1158. modes may be used to generate an address
  1159.  
  1160. 7.1) Description of directory tree
  1161.  
  1162. Sources to this compiler are included in seperate packages.
  1163.  
  1164. Sources should be generic; that is they should work on any architecture
  1165. where the byte size is 8 bits.  However, I use weird tab settings in my 
  1166. editor.  If you want to comprehend the sources get a beautifier of some
  1167. sort and run the sources through it first;  or set your editor tab 
  1168. setting to 2 to see what I see.
  1169.  
  1170.  
  1171. The directory structure is:     
  1172.  
  1173. CLIBS 
  1174.     various sources for runn-time library       
  1175. DOC          
  1176.     documentation
  1177. EXAMP        
  1178.     a simple example
  1179.     (there is a more complex one in clibs\startup\test)
  1180. INCLUDE
  1181.     compiler header files
  1182. OBJECT  
  1183.     compiler make/objeect files     
  1184. SOURCE       
  1185.     compiler source files
  1186.  
  1187. There are two groups of sources:
  1188.    1) the compiler
  1189.     in the SOURCE, INCLUDE, OBJECT directories
  1190.    2) libraries you can use in conjunction
  1191.       with the compiler to gennerate programs (target run-time libraries)
  1192.     in the CLIBS directory
  1193.  
  1194. I often use the set of triple directories:
  1195.     SOURCE
  1196.     OBJECT
  1197.     INCLUDE        
  1198.  
  1199. for a given project so I won't clutter up a single directory with dozens
  1200. of files.  When this triple comes up, sources are inn the SOURCE directory,
  1201. headers the sources depend on are in the INCLUDE direcorty, and you can
  1202. expect me to chdir to the OBJECT directory to compile the program...
  1203. thus you will find the make file there.
  1204.  
  1205. For these triples you thus have to use an include path which consists of
  1206. the INCLUDE directory when you compile the source files.
  1207.  
  1208. proto.bat generates the file INCLUDE\CC.P; which is a protootype file
  1209. I'm using to keep the compiler honest with me.  You shouldn't have
  1210. to change that unless you make major changes to the sources... but you can
  1211. edit CC.P directly and put new prototypes in if you want.  I often do.
  1212. I only use proto.bat when I'm making major changes to the compiler.
  1213.  
  1214. 7.2) Porting
  1215.  
  1216. This version of the compiler is intended to be portable; one need only
  1217. rewrite the back end for the given target.  This portability probably
  1218. extends only to processors with a 'byte' architecture.
  1219.  
  1220. The following symbols have to be defined on the command line:
  1221.  
  1222. -DPROGNAME="CC386"         ; Name of the program whnich will 
  1223.         appear in the bannder
  1224.  
  1225.  -DENVNAME="CC386"        ; Name of the environment variable to
  1226.          consult for command line parameters
  1227.          
  1228. -DGLBDEFINE="_i386_"         ; Symbol to define in the source; can
  1229.         be used to identify processor-specific needs
  1230. -DSOURCEXT=".ASM"         ; Extnension to use on the output file
  1231.  
  1232. These definitions are imported by CMAIN.C to define the program
  1233. environment.  I have shown you the definitions used by the 386 
  1234. compiler; change them as necessary for your target.
  1235.  
  1236. The following files comprise the 386 backend.  They should be all you 
  1237. have to change to port the compiler to a new processor.  I suggest you 
  1238. rename them to something else before changing them:
  1239.  
  1240. an386.c      - Register optimization
  1241. reg386.c    - Register allocation for expressions
  1242. conf386.c    - configuration; int sizes and free registers and such
  1243. outas386.c    - outputs ASM code
  1244. gexpr386.c    - turn the expression parse trees into code
  1245. gstmt386.c    - turn the stmt parse trees into code
  1246. peep386.c    - Peephole analysis for this processor
  1247.  
  1248. For more information on porting contact the author of the code.
  1249.  
  1250. David Lindauer (gclind01@starbase.spd.louisville.edu)
  1251.  
  1252.  
  1253.                                             
  1254.                                                 
  1255.                                                 
  1256.                                                 
  1257.                                                 
  1258.                                                 
  1259.                             
  1260.                                                 
  1261.                                                 
  1262.                                                 
  1263.                                                 
  1264.                                                 
  1265.                                                 
  1266.                                                 
  1267.